# Maintainer: Peter Budai <peterbudai@hotmail.com>

# PLEASE NOTE: due to npm bug the build process is stuck if
# logging is enabled. In order to build this recipe you need
# to TURN OFF logging and build like:
# makepkg -sCf

_realname=notebook
pkgbase=mingw-w64-python-${_realname}
pkgname=("${MINGW_PACKAGE_PREFIX}-python3-${_realname}")
pkgver=5.7.4
pkgrel=1
pkgdesc="The language-agnostic HTML notebook application for Project Jupyter"
arch=('any')
url="https://github.com/jupyter/notebook"
license=('BSD')

depends=("${MINGW_PACKAGE_PREFIX}-python3"
         "${MINGW_PACKAGE_PREFIX}-python3-jupyter_core"
         "${MINGW_PACKAGE_PREFIX}-python3-jupyter_client"
         "${MINGW_PACKAGE_PREFIX}-python3-jupyter-nbformat"
         "${MINGW_PACKAGE_PREFIX}-python3-jupyter-nbconvert"
         "${MINGW_PACKAGE_PREFIX}-python3-ipywidgets"
         "${MINGW_PACKAGE_PREFIX}-python3-jinja"
         "${MINGW_PACKAGE_PREFIX}-python3-traitlets"
         "${MINGW_PACKAGE_PREFIX}-python3-tornado"
         "${MINGW_PACKAGE_PREFIX}-python3-terminado"
         "${MINGW_PACKAGE_PREFIX}-python3-send2trash"
         "${MINGW_PACKAGE_PREFIX}-python3-prometheus-client"
#         "${MINGW_PACKAGE_PREFIX}-mathjax"
         )
makedepends=("${MINGW_PACKAGE_PREFIX}-python3-setuptools"
             "${MINGW_PACKAGE_PREFIX}-python3-setuptools"
             "${MINGW_PACKAGE_PREFIX}-nodejs"
             "${MINGW_PACKAGE_PREFIX}-yarn"
             "${MINGW_PACKAGE_PREFIX}-bower"
             )

source=("$pkgname-$pkgver.tgz::https://github.com/jupyter/notebook/archive/$pkgver.tar.gz"
        "001-jupyter-notebook-MINGW.patch")
sha256sums=('c26c67ee16a64b6d2444884b73c399d8020f598f833f4165864e31f28d1c410e'
            '0362ef7944792188d8202bdedd7b51b9a0a06867ea43f480bf8318b163d3b616')

prepare(){
  cd "$srcdir/${_realname}-$pkgver"
  patch -p1 -i ${srcdir}/001-jupyter-notebook-MINGW.patch
}

build() {

  cd "$srcdir/${_realname}-$pkgver"

  ${MINGW_PREFIX}/bin/python3 setup.py build
}

package() {

  cd "$srcdir/${_realname}-$pkgver"
  MSYS2_ARG_CONV_EXCL="--prefix=;--install-scripts=;--install-platlib=" \
  ${MINGW_PREFIX}/bin/python3 setup.py install --prefix=${MINGW_PREFIX} \
    --root="${pkgdir}" --optimize=1 --skip-build

  install -Dm644 COPYING.md "${pkgdir}${MINGW_PREFIX}/share/licenses/python3-${_realname}/LICENSE"

  # Remove hard coded library paths in css map files
  local TOKEN_TOREPLACE=$(cygpath -am ${srcdir}/${_realname}-$pkgver/${_realname}/static)

  pushd "${pkgdir}${MINGW_PREFIX}/lib/python3.7/site-packages/notebook/static/style/" > /dev/null
  sed -s "s|${TOKEN_TOREPLACE}|..|g" -i ./ipython.min.css.map
  sed -s "s|${TOKEN_TOREPLACE}|..|g" -i ./style.min.css.map
  popd > /dev/null
}
